package com.produce.user.controller;


import com.common.dao.base.constant.SystemStaticConst;
import com.common.dao.base.controller.BaseController;
import com.common.dao.base.service.BaseService;
import com.linzf.common.util.DateUtil;
import com.produce.user.entity.Dict;
import com.produce.user.service.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 类描述：数据字典的controller
 * @author linzf
 */
@RestController
@RequestMapping(value = "/dict")
public class DictController extends BaseController<Dict> {

    @Autowired
    private DictService dictService;

    @Override
    protected BaseService<Dict> getService() {
        return this.dictService;
    }

    /**
     * 功能描述：更新数据字典状态
     * @param entity
     * @return
     */
    @PostMapping("operateDict")
    public Map<String,Object> operateDict(@RequestBody Dict entity){
        Map<String,Object> result = new HashMap<>(2);
        if(dictService.operateDict(entity)>0){
            result.put(SystemStaticConst.RESULT, SystemStaticConst.SUCCESS);
            result.put(SystemStaticConst.MSG,"更新数据字典状态成功！");
        }else{
            result.put(SystemStaticConst.RESULT, SystemStaticConst.FAIL);
            result.put(SystemStaticConst.MSG,"更新数据字典状态失败！");
        }
        return result;
    }

    /**
     * 功能描述：实现保存数据字典数据
     * @param entity
     * @return
     * @throws Exception
     */
    @Override
    public Map<String, Object> save(@RequestBody Dict entity) throws Exception {
        entity.setCrtDate(DateUtil.currentMillitm());
        return super.save(entity);
    }

    /**
     * 功能描述：实现更新数据字典数据
     * @param entity
     * @return
     * @throws Exception
     */
    @Override
    public Map<String, Object> update(@RequestBody Dict entity) throws Exception {
        return super.update(entity);
    }

    /**
     * 功能描述：实现删除数据字典数据
     * @param entity
     * @return
     * @throws Exception
     */
    @Override
    public Map<String, Object> remove(@RequestBody Dict entity) throws Exception {
        return super.remove(entity);
    }

}
